﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SimpleWeather.BusinessEntities;
using SimpleWeather.DataControllers;
using StyleMVVM.DependencyInjection;
using StyleMVVM.View;
using StyleMVVM.ViewModel;
using Windows.UI.Xaml.Navigation;

namespace SimpleWeather.ViewModels
{
	public class ForecastDetailsPageViewModel : PageViewModel
	{
		private CompleteDayForecast forecast;

		[Import]
		public IWeatherServiceController DataController { get; set; }

		public string Title
		{
			get
			{
				if (SelectedForecast != null)
				{
					return string.Format("{0} {1}", SelectedForecast.CityDisplayName, SelectedForecast.DateDisplay);
				}
				return null;
			}
		}

		public CompleteDayForecast SelectedForecast
		{
			get { return forecast; }
			set
			{
				SetProperty(ref forecast, value);

				OnPropertyChanged("Title");
			}
		}

		public IEnumerable<CompleteDayForecast> AllForecasts
		{
			get
			{
				if (forecast != null)
				{
					return forecast.Parent as IEnumerable<CompleteDayForecast>;
				}

				return null;
			}
		}

		protected override void OnNavigatedTo(object sender, StyleNavigationEventArgs e)
		{
			string forecastID = NavigationParameter as string;

			if (forecastID != null)
			{
				SelectedForecast = DataController.GetForecast(forecastID);

				OnPropertyChanged("AllForecasts");
			}
		}
	}
}
